/**
 * 
 */

/**
 * @author Robert Pethes
 *
 */

import HMM.*;
import CorpusConverter.*;
import TrainingData.*;

import java.io.*;
import java.util.Vector;

public class HMMIRLMain {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			File textFile = new File("c:\\hmm\\test.out");
			
			TextCorpus corpus = new TextCorpus(textFile);
			
			TweakedPennTreebankConverter converter = new TweakedPennTreebankConverter(corpus,"***",1);
			
			TrainingInstanceCollection data = converter.convert();
			
			TrainingInstanceCollection testData = new TrainingInstanceCollection(data.getNumStates(), data.getNumEmissions(), new Vector<TrainingInstance>());
			
			TrainingInstanceCollection trainingData = new TrainingInstanceCollection(data.getNumStates(), data.getNumEmissions(), new Vector<TrainingInstance>());

			data.split(.8, 1, trainingData, testData);
			
			HMM derekasHMM = new HMM(trainingData);
			
			DoubleSparseMatrix transitionMx = derekasHMM.getTransitionMatrix();
			
			DoubleSparseMatrix emissionMx = derekasHMM.getEmissionMatrix();
			
			//transitionMx.scalarTimes(0.0); // uncomment these if you want to start training a method from scratch -- G. 
			//emissionMx.scalarTimes(0.0);
			
			TrainingMethod perceptron = new Perceptron(20, trainingData, testData);
			
			TrainingMethod maxMargin = new MaxMargin(20, trainingData, testData, 1);
			
			TrainingMethod policyMatching = new PolicyMatching(20, trainingData, testData, .1);
			
			derekasHMM.train(maxMargin);
			
			derekasHMM.test(testData, System.out, true);
			
			/*for (TrainingInstance instance : data) {
				
				int[] states = instance.getStates();
				int[] emissions = instance.getEmissions();
				
				for (int i = 0; i < states.length; i++){
					System.out.print(Integer.toString(states[i]) + " ");
				} 
				System.out.println("");
				
				for (int i = 0; i < emissions.length; i++){
					System.out.print(Integer.toString(emissions[i]) + " ");
				} 
				
				System.out.println("");
				System.out.println("*****************************************************");
			}*/
			
			/*
			do {
				line = corpus.getNextSentence();
				
				if (line!=null)
					System.out.println("1. sor:" + line);
			} while (line!=null);
			*/
			
		}catch (Exception e){
			System.out.println(e.getClass().getName());
			System.out.println("Kellemetlen exception:");
			System.out.println(e.getMessage());
		}
	}
}
